package com.ftg.learn.chapter09.settest;

import java.util.*;

/**
 * 去除List中重复的元素
 *
 * @author lijiaxin
 * @version 1.0
 * @date 2023/8/16 11:09
 */

public class Move {

    public static void jiaoji(Set<Integer> set1,Set<Integer> set2){
//        判断两个Set是否有交集,差集
        Set<Integer> result=new HashSet<>();
        System.out.println(set1);
        System.out.println(set2);
        result.addAll(set1);
        result.retainAll(set2);
        System.out.println( "交集"+result);
        result.addAll(set1);
        result.removeAll(set2);
        System.out.println( "差集"+result);
        result.addAll(set1);
        result.addAll(set2);
        System.out.println( "并集"+result);
    }

    public static void repeat(List<Integer> list){
//        使用Set找出数组中的重复元素
        Set<Integer> set=new HashSet<>(list);
        System.out.println(list);
        System.out.println(set);

    }

    public static void main(String[] args) {
//        List<Integer> list= Arrays.asList(1,1,2,2,3,3,4,5,6);
//        Set<Integer> set=new HashSet<>(list);
//        System.out.println(set);

//        Set<Integer> set=new HashSet<>();
//        System.out.println("set1里面的个数为");
//        Scanner count=new Scanner(System.in);

        Set<Integer> set1=new HashSet<>(Arrays.asList(12,22,33));
        Set<Integer> set2=new HashSet<>(Arrays.asList(12,22,334));
        jiaoji(set1,set2);

//        List<Integer> list=Arrays.asList(1,1,1,3,4,5,2,2,7);
//        repeat(list);
    }



}
